<?php
/**
 * User: b179a9
 * Date: 9/20/11
 * Time: 6:23 PM
 */

class App_Plugin_Remember extends Zend_Controller_Plugin_Abstract
{

    function preDispatch(Zend_Controller_Request_Abstract $request)
    {
        $auth = Zend_Auth::getInstance();
        if (!$auth->hasIdentity()) {
            if (array_key_exists('user', $_COOKIE)) {
                $user = $_COOKIE['user'];

                $params = explode('|', $user);
                $usersManager = new \Managers\Users();
                $user = $usersManager->isValid($params[0], $params[1]);

                if ($user) {
                    $result = $usersManager->doLogin($user);
                } else {
                    //Удаляем фальшивый куки.
                    setcookie('user', null, time());
                }

            }
        }
    }

}
